﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_NH.DB_Map.ywxt
{
    using NHibernate;
    using NHibernate.Mapping.ByCode;
    using NHibernate.Mapping.ByCode.Conformist;

    using DB_NH.DB_Model.ywxt;

    public class Enterprise_Map : ClassMapping<Enterprise>
    {
        public Enterprise_Map()
        {
            //映射ID
            Id(x => x.Id, map =>
            {
                map.Column("ent_id");
                map.Length(40);
            });

            Property(x => x.IsValid, map =>
            {
                map.Column("is_valid");
            });
            Property(x => x.CreateDate, map =>
            {
                map.Column("create_date");
            });

            Property(x => x.AreaName, map =>
            {
                map.Column("area_id");
                map.Length(40);
            });
            Property(x => x.AddressCN, map =>
            {
                map.Column("ent_address_cn");
                map.Length(500);
            });
            Property(x => x.AddressEN, map =>
            {
                map.Column("ent_address_en");
                map.Length(500);
            });
            Property(x => x.BusinessScope, map =>
            {
                map.Column("ent_business_scope");
                map.Length(500000000);
            });
            Property(x => x.CreationDate, map =>
            {
                map.Column("ent_create_date");
            });
            Property(x => x.EntSize, map =>
            {
                map.Column("ent_ent_size_id");
                map.Length(40);
            });
            Property(x => x.EntFlag, map =>
            {
                map.Column("ent_flag");
                map.Length(40);
            });
            Property(x => x.LegalPersonNameCN, map =>
            {
                map.Column("ent_legal_person_cn");
                map.Length(200);
            });
            Property(x => x.LegalPersonNameEN, map =>
            {
                map.Column("ent_legal_person_en");
                map.Length(200);
            });
            Property(x => x.LegalPersonGender, map =>
            {
                map.Column("ent_legal_person_gender");
                map.Length(40);
            });
            Property(x => x.LinkUserDesktophone, map =>
            {
                map.Column("ent_link_user_desktophone");
                map.Length(40);
            });
            Property(x => x.LinkUserEmail, map =>
            {
                map.Column("ent_link_user_email");
                map.Length(200);
            });
            Property(x => x.LinkUserFax, map =>
            {
                map.Column("ent_link_user_fax");
                map.Length(40);
            });
            Property(x => x.LinkUserMobilephone, map =>
            {
                map.Column("ent_link_user_mobilephone");
                map.Length(40);
            });
            Property(x => x.LinkUserName, map =>
            {
                map.Column("ent_link_user_name");
                map.Length(200);
            });
            Property(x => x.LinkUserPosition, map =>
            {
                map.Column("ent_link_user_position");
                map.Length(200);
            });

            Property(x => x.NameCN, map =>
            {
                map.Column("ent_name_cn");
                map.Length(200);
            });

            Property(x => x.NameEN, map =>
            {
                map.Column("ent_name_en");
                map.Length(200);
            });
            Property(x => x.PostCode, map =>
            {
                map.Column("ent_post_code");
                map.Length(50);
            });
            Property(x => x.SimpleCode, map =>
            {
                map.Column("ent_simplecode");
                map.Length(40);
            });
            Property(x => x.TypeId, map =>
            {
                map.Column("ent_type_id");
                map.Length(50);
            });
            Property(x => x.MarkDate, map =>
            {
                map.Column("mark_date");
            });
            Property(x => x.MarkFlag, map =>
            {
                map.Column("mark_flag");
            });

            Property(x => x.TaxpayerIDNumber, map =>
            {
                map.Length(50);
            });

            Property(x => x.OpeningBank, map =>
            {
                map.Length(200);
            });

            Property(x => x.BasicAccount, map =>
            {
                map.Length(200);
            });

            Property(x => x.IsValueAddTaxpayer, map =>
            {

            });

            Property(x => x.Remark, map =>
            {
                map.Length(8000000);
            });

            Property(x => x.BidderCode, map =>
            {
                map.Length(100);
            });

            Property(x => x.CACode, map =>
            {
                map.Length(100);
            });

            Property(x => x.IndustryCode, map =>
            {
                map.Length(100);
            });

            Property(x => x.RegCapital, map =>
            {
                
            });

            Property(x => x.RegCapCurrency, map =>
            {
                map.Length(40);
            });

            Property(x => x.CreditRate, map =>
            {
                map.Length(40);
            });

            //审核用户
            ManyToOne(x => x.MarkUser, map =>
            {
                map.Column("mark_user_id");
            });


            //投标人参与的项目列表
            Bag(x => x.Projects, map =>
            {
                map.Key(keyMapper => keyMapper.Column("ent_id"));
                map.Cascade(Cascade.None);
            }, rel => rel.OneToMany());

            //投标人的用户列表
            Bag(x => x.EntUsers, map =>
            {
                map.Key(keyMapper => keyMapper.Column("ent_id"));
                map.Cascade(Cascade.None);
                map.Inverse(false);
            }, rel => rel.OneToMany());

            //企业的联系人列表
            Bag(x => x.EntLinkers, map =>
            {
                map.Key(keyMapper => keyMapper.Column("ent_id"));
                map.Cascade(Cascade.None);
                map.Inverse(false);
            }, rel => rel.OneToMany());

            Table("t_enterprise");

            //不进行创建
            //SchemaAction(NHibernate.Mapping.ByCode.SchemaAction.None);
        }
    }
}
